import java.util.*;

public class idsangpingjiage {
    private  String id;
    private  String name;
    private  double price;

    @Override
    public String toString() {
        return id+name+price;
    }

    public idsangpingjiage(String id, String name, double price){
        this.id =id;
        this.name=name;
        this.price=price;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public static void main(String[] args) {
        Map<String, List<idsangpingjiage>>allMap=new HashMap<>();
        Scanner scanner=new Scanner(System.in);
        while (true){
            System.out.println("查询:1");
            System.out.println("请输入学号ID：");
            System.out.println("添加成员：id");
            System.out.println("添加书本：name");
            System.out.println("遍历：list");
            System.out.println("退出：exst");
            String cmd=scanner.nextLine();

            switch (cmd){
                case "1":
                    System.out.println("输入学号");
                    String ID=scanner.nextLine();
                    List<idsangpingjiage> v=allMap.get(ID);
                    System.out.println("书本以及价格："+v+"元");
                    break;
                case "id":
                    System.out.println("请输入id");
                    String id=scanner.nextLine();
                    System.out.println("书本名称");
                    String name=scanner.nextLine();
                    System.out.println("书本价格");
                    double price=scanner.nextDouble();
                    idsangpingjiage book=new idsangpingjiage(id,name,price);
                    allMap.computeIfAbsent(id,k->new ArrayList<>()).add(book);
                    break;
                case "name":
                    System.out.println("请输入学号：");
                    String i=scanner.nextLine();
                    if (!allMap.containsKey(i)){
                        allMap.put(i,new ArrayList<>());
                    }
                    System.out.println("请输入新书本:");
                    String n=scanner.nextLine();
                    System.out.println("书本价格");
                    double p=scanner.nextDouble();
                    idsangpingjiage p1=new idsangpingjiage(i,n,p);
                    allMap.get(i).add(p1);
                    break;
                case  "list":
                    for (Map.Entry<String,List<idsangpingjiage>>entry:allMap.entrySet()){
                        System.out.println("学号ID："+entry.getKey());
                        for (idsangpingjiage b:entry.getValue()){
                            System.out.println("书本信息:"+b+"元");
                        }

                    }
                        break;

                case "exst" :
                    return;
            }
        }

    }
}
